<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
<title>业主管理</title>
<!-- Bootstrap -->
<link href="/SmartCommunity/css/pc/bootstrap.css" rel="stylesheet">
<link href="/SmartCommunity/css/pc/main.css" rel="stylesheet">
</head>
<body>
	<nav class="navbar navbar-inverse navbar-fixed-top">
	<div class="container">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed"
				data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
				aria-expanded="false">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand  smart" href="/SmartCommunity/views/pc/smart.html">SMART</a>
		</div>
		<!-- Collect the nav links, forms, and other content for toggling -->
		<div class="collapse navbar-collapse"
			id="bs-example-navbar-collapse-1">
			<ul class="nav navbar-nav">
			</ul>
			<form class="navbar-form navbar-right">
				<a class="btn btn-primary" id="quit">退出</a>
			</form>
		</div>
	</div>
	</nav>
<div class="col-md-2"></div>
	<div class="maincontentinner col-md-8">
		<h4 class="widgettitle">业主信息记录表</h4>
		<div class="dataTables_filter">
		&nbsp;&nbsp;<label>姓名</label>
		<input type="text" id="search_name" class="auth_search"  />
		&nbsp;&nbsp;<label>手机号</label>
		<input type="text" id="search_phone" class="auth_search1" /> 
		&nbsp;&nbsp;<label>楼宇</label>
		<input type="text" id="search_building" class="auth_search" placeholder="1,2……"/> 
		&nbsp;&nbsp;<label>房间</label>
		<input type="text" id="search_room" class="auth_search"  placeholder="101,1911……"/> 
		<input type="button" value="搜索" id="search_btn" />
			<div class="add_btn">
				<label>添加：</label> <a href="javascript:void(0);"
					onclick="add(this);"><span class="glyphicon glyphicon-plus"
					aria-hidden="true"></a></span>
			</div>
		</div>
		<table class="table table-bordered responsive">
			<thead>
				<tr>
					<th class="center">姓名</th>
					<th class="center">手机</th>
					<th class="center">楼宇</th>
					<th class="center">房间</th>
					<th class="center">身份</th>
					<th class="center">修改</th>
					<th class="center">删除</th>
				</tr>
			</thead>
			<tbody id="table_body">
				<tr class="template-auth" style="display: none">
					<td class="name center"></td>
					<td class="phone center"></td>
					<td class="building center"></td>
					<td class="room center"></td>
					<td class="type center"></td>
					<td class="modify center"><a href="javascript:void(0);"
						onclick="modify(this);"><span class="glyphicon glyphicon-pencil"
							aria-hidden="true"></a></span></td>
					<td class="center"><a href="javascript:void(0);"
						onclick="delete_add(this);"><span
							class="glyphicon glyphicon-trash" aria-hidden="true"></a></span></td>
				</tr>

			</tbody>
		</table>
		<div id="page1" class="page_foot"></div>
	</div>

	<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">修改业主信息</h4>
				</div>
				<div class="modal-body">
					<form>
						<div class="form-group">
							<label for="modify_name" class="control-label">姓名</label> <input
								type="text" class="form-control" id="modify_name">
						</div>
						<div class="form-group">
							<label for="modify_phone" class="control-label">手机号</label> <input
								type="text" class="form-control" id="modify_phone">
						</div>
						<div class="form-group">
							<label for="modify_building" class="control-label">楼宇</label> <input
								type="text" class="form-control" id="modify_building">
						</div>
						<div class="form-group">
							<label for="modify_room" class="control-label">房间</label> <input
								type="text" class="form-control" id="modify_room">
						</div>
						<div class="form-group">
							<label for="modify_type" class="control-label">身份</label> <select
								class="form-control" id="modify_type">
								<option value="0">户主</option>
								<option value="1">家人</option>
								<option value="2">租户</option>
							</select>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" id="btn_sure" class="btn btn-primary"
						onclick="submitOK(this)">提交</button>
				</div>
			</div>
		</div>
	</div>

	<div class="modal fade" id="exampleModalAdd" tabindex="-1"
		role="dialog" aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabelAdd">添加业主信息</h4>
				</div>
				<div class="modal-body">
					<form>
						<div class="form-group">
							<span class="imp">*</span><label for="add_name" class="control-label">姓名</label>&nbsp;&nbsp;<span class="imp error_name" style="display:none;">请输入用户名字</span> <input
								type="text" class="form-control" id="add_name">
						</div>
						<div class="form-group">
							<span class="imp">*</span><label for="add_phone" class="control-label">手机号</label>&nbsp;&nbsp;<span class="imp error_phone" style="display:none;">请输入合法的手机号</span> <input
								type="text" class="form-control" id="add_phone">
						</div>
						<div class="form-group">
							<span class="imp">*</span><label for="add_building" class="control-label">楼宇</label> &nbsp;&nbsp;<span class="imp error_building" style="display:none;">请输入楼宇号</span><input
								type="text" class="form-control" id="add_building">
						</div>
						<div class="form-group">
							<span class="imp">*</span><label for="add_room" class="control-label">房间</label>&nbsp;&nbsp;<span class="imp error_room" style="display:none;">请输入房间号</span><input
								type="text" class="form-control" id="add_room">
						</div>
						<div class="form-group">
							<span class="imp">*</span><label for="add_type" class="control-label">身份</label> &nbsp;&nbsp;<span class="imp error_type" style="display:none;">请选择业主身份</span><select
								class="form-control" id="add_type">
								<option value="">请选择</option>
								<option value="0">户主</option>
								<option value="1">家人</option>
								<option value="2">租户</option>
							</select>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" id="btn_sure_add" class="btn btn-primary"
						onclick="submitOKAdd(this)">提交</button>
				</div>
			</div>
		</div>
	</div>
	<!-- Include all compiled plugins (below), or include individual files as needed -->
	<script src="/SmartCommunity/js/pc/jquery.js"></script>
	<script src="/SmartCommunity/js/pc/init.js"></script>
	<script src="/SmartCommunity/js/pc/page.js"></script>
	<script src="/SmartCommunity/js/pc/bootstrap.js"></script>
	    <script src="/SmartCommunity/js/pc/jquery.atmosphere.js"></script>
	<script>
		init();
		var page_num=1;
		ajax_trans("/SmartCommunity/pc/get_user_list?page="+page_num);
		function ajax_trans(url_http){
			$.ajax({
				type: "POST",
				url: url_http,
				contentType: "application/json;charset=utf-8",
				success: function(data){
					//alert("success method");
					//alert(data);
					var arr=eval("("+data+")");
					//alert(arr);
					//var arr=data;
					var pages = Math.ceil(parseInt(arr.count)/10);
					$("#page1").unbind();
					count_pages(pages,null,null,null,null);
					arr1=arr.content;
					for(var i =0; i <arr1.length; i++){
				    	var row = $(".template-auth").eq(0).clone();
						row.find(".name").text(arr1[i].name);
						row.find(".phone").text(arr1[i].telphone_num);
						row.find(".building").text(arr1[i].buildingNo);
						row.find(".room").text(arr1[i].roomNo);
						if(arr1[i].type==0){
							sel="户主";
						}
						else if(arr1[i].type==1){
							sel="家人";
						}
						else{
							sel="租户";
						}
						row.find(".type").text(sel);
						row.attr("id",arr1[i].userID);
						if(i==0){
							$("#table_body").html("");
						}
						row.css("display", "table-row");
						row.appendTo("#table_body");   
				    }
				},
				error: function(data){
					alert("error");	
				} 
				});
		}
		
		function ajax_trans_page(url_http,search_name,search_phone,search_building,search_room){
			$.ajax({
				type: "POST",
				url: url_http,
				//contentType: "application/json;charset=utf-8",
				data:{search_name:search_name,search_phone:search_phone,search_building:search_building,search_room:search_room},
				success: function(data){
					//alert("success method");
					//alert(data);
					var arr=eval("("+data+")");
					arr1=arr.content;
					for(var i =0; i <arr1.length; i++){
				    	var row = $(".template-auth").eq(0).clone();
						row.find(".name").text(arr1[i].name);
						row.find(".phone").text(arr1[i].telphone_num);
						row.find(".building").text(arr1[i].buildingNo);
						row.find(".room").text(arr1[i].roomNo);
						if(arr1[i].type==0){
							sel="户主";
						}
						else if(arr1[i].type==1){
							sel="家人";
						}
						else{
							sel="租户";
						}
						row.find(".type").text(sel);
						row.attr("id",arr1[i].userID);
						if(i==0){
							$("#table_body").html("");
						}
						row.css("display", "table-row");
						row.appendTo("#table_body");   
				    }
				},
				error: function(data){
					alert("error");	
				} 
				});
		}
function count_pages(num,search_name,search_phone,search_building,search_room){
	//alert("a");
	 $("#page1").createPage({
	        pageCount:num,
	        current:page_num,
	        backFn:function(p){
	        	alert(p);
	        	page_num=p;
	        	ajax_trans_page("/SmartCommunity/pc/get_user_list?page="+p,search_name,search_phone,search_building,search_room);
	        }		
	    });	
}	

		$("#search_btn").click(function(){
			var search_name=$("#search_name").val();
			var search_phone=$("#search_phone").val();
			var search_building=$("#search_building").val();
			var search_room=$("#search_room").val();
			//if(search_name||search_phone||search_building||search_room){
			$.ajax({
				type:"POST",
				url:"/SmartCommunity/pc/get_user_list",
				//contentType:"application/json;charset=utf-8",
				data:{search_name:search_name,search_phone:search_phone,search_building:search_building,search_room:search_room},
				success:function(data){
					//alert("search success method ");
					var arr=eval("("+data+")");
					//alert(arr.count);
					if(arr.count!=0)
					{
						page_num=1;
						var pages = Math.ceil(parseInt(arr.count)/10);
						$("#page1").unbind();
						count_pages(pages,search_name,search_phone,search_building,search_room);
						arr1=arr.content;
						for(var i =0; i <arr1.length; i++){
					    	var row = $(".template-auth").eq(0).clone();
							row.find(".name").text(arr1[i].name);
							row.find(".phone").text(arr1[i].telphone_num);
							row.find(".building").text(arr1[i].buildingNo);
							row.find(".room").text(arr1[i].roomNo);
							if(arr1[i].type==0){
								sel="户主";
							}
							else if(arr1[i].type==1){
								sel="家人";
							}
							else{
								sel="租户";
							}
							row.find(".type").text(sel);
							row.attr("id",arr1[i].userID);
							if(i==0){
								$("#table_body").html("");
							}
							row.css("display", "table-row");
							row.appendTo("#table_body");   
					    }
					}
					else
					{
						alert("未搜索到相关内容");
						$(".template-auth").css("display","none");
					}
				},
				error:function(){
					alert("error");
				}
			});
			/*
			}
			else{
				alert("请输入搜索内容");
			}
			*/
			
		});
		
		function modify(obj){
			var par=$(obj).parent().parent();
			var temp=par.attr("id");
			//alert(temp);
			var tds=par.find('td');
	    	$('#modify_name').val(tds.eq(0).text());
			$('#modify_phone').val(tds.eq(1).text()); 
			$('#modify_building').val(tds.eq(2).text());
			$('#modify_room').val(tds.eq(3).text());
			if(tds.eq(4).text()=="户主"){
				sel=0;
			}
			else if(tds.eq(4).text()=="家人"){
				sel=1;
			}
			else{
				sel=2;
			}
			$("#modify_type").val(sel);
			$("#btn_sure").addClass(temp);
			$('#exampleModal').modal('show');
		}
		
		function submitOK(e){
			var id1=$(e).attr("class");
			var group=id1.split(" ");
            //alert(group[1]);
			//alert(group[2]);
			var a=$("#"+group[2]).index();
			var modify_name=$('#modify_name').val();
			var modify_phone= $('#modify_phone').val(); 
			var modify_building=$('#modify_building').val();
			var modify_room=$('#modify_room').val();
			var modify_type=$("#modify_type").val();
			$.ajax({
				type:"POST",
				url:"/SmartCommunity/pc/update_user",
				contentTpye:"application/json;charset=utf-8",
				data:{name:modify_name,telephoneNum:modify_phone,building:modify_building,room:modify_room,type:modify_type,id:group[2]},
				success:function(data)
				{
					//alert("modify success method");
					//alert(data);
					if(data=="true"){
						alert("修改成功");
						ajax_trans_page("/SmartCommunity/pc/get_user_list?page="+page_num,null,null,null);
					}
					else{
						alert("修改失败！");
					}
				},
				error:function(data)
				{
					//var arr=eval(data);
					//alert(arr);
					alert("error");
				}
			});
			
		}
		function add(){
			$(".error_name").css("display","none");
			$(".error_phone").css("display","none");
			$(".error_building").css("display","none");
			$(".error_room").css("display","none");
			$(".error_type").css("display","none");
			$('#exampleModalAdd').modal('show');
		}
		function submitOKAdd(e){
			var add_name=$('#add_name').val();
			var add_phone= $('#add_phone').val(); 
			var add_building=$('#add_building').val();
			var add_room=$('#add_room').val();
			var add_type=$("#add_type").val();
			if(add_name==""){
				$(".error_name").css("display","inline");
				$('#add_name').focus();
				return false;
			}else{
				$(".error_name").css("display","none");
			}
			var regu = /^[1][0-9][0-9]{9}$/;
			var re = new RegExp(regu);
			if (!re.test(add_phone)) { 
				$(".error_phone").css("display","inline");
				$('#add_phone').focus();
				return false;
			}else{
				$(".error_phone").css("display","none");
			}
			if(add_building==""){
				$(".error_building").css("display","inline");
				$('#add_building').focus();
				return false;
			}
			else{
				$(".error_building").css("display","none");
			}
			if(add_room==""){
				$(".error_room").css("display","inline");
				$('#add_room').focus();
				return false;
			}
			else{
				$(".error_room").css("display","none");
			}
			if(add_type==""){
				$(".error_type").css("display","inline");
				return false;
			}
			else{
				$(".error_type").css("display","none");
			}
			$.ajax({
				type:"POST",
				url:"/SmartCommunity/pc/add_user",
				contentTpye:"application/json;charset=utf-8",
				data:{name:add_name,telephoneNum:add_phone,building:add_building,room:add_room,type:add_type},
				success:function(data){
					if(data=="true"){
						alert("添加成功");
						ajax_trans_page("/SmartCommunity/pc/get_user_list?page="+page_num,null,null,null,null);
					}
					else{
						alert("添加失败！");
					}
				},
				error:function(){
					alert("error");
				}
			});
			
		}
		function delete_add(e){
			var par=$(e).parent().parent();
			var id_d=par.attr("id");
			alert(id_d);
			var temp=par.index();
			if (confirm("你确定删除吗？")) { 
				$.ajax({
					type:"POST",
					url:"/SmartCommunity/pc/delete_user",
					contentTpye:"application/json;charset=utf-8",
					data:{id:id_d},
					success:function(data){
						if(data=="true"){
							ajax_trans_page("/SmartCommunity/pc/get_user_list?page="+page_num,null,null,null,null); 
						}
						else{
							alert("删除失败！");
						}
					},
					error:function(){
						alert("error");
					}
				});
				  
		        }  	
			
			 		
		}
	</script>
</body>

</html>